package cn.gov.ssxmzj.controller;

import cn.gov.ssxmzj.entry.Result;
import cn.gov.ssxmzj.service.ManagerService;
import cn.gov.ssxmzj.service.VillageService;
import cn.gov.ssxmzj.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;

@Controller
@RequestMapping("/manager")
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    @Autowired
    private VillageService villageService;

    @ResponseBody
    @RequestMapping("/login")
    public Result login(String username,String password,String code,HttpSession session){
        return managerService.login(username,password,code,session);
    }

    @ResponseBody
    @RequestMapping("/unlock")
    public Result unlock(String username,String password){
        return managerService.unlock(username,password);
    }

    @ResponseBody
    @RequestMapping("/getImgCode")
    public void getImgCode(HttpServletRequest request, HttpServletResponse response){
        Utils.getRandomCode(request,response);
    }


    @ResponseBody
    @RequestMapping("/getManagerInfo")
    public Result getManagerInfo(String managerId,String searchName,int page,int limit){
        return managerService.getManagerInfo(managerId,searchName,page,limit);
    }

    @ResponseBody
    @RequestMapping("/getNewsByType")
    public Result getNewsByType(String newsType,String searchName,int page, int limit){
        return managerService.managerGetNewsInfo(newsType,searchName,page,limit);
    }

    @ResponseBody
    @RequestMapping("/deleteNews")
    public Result deleteNews(String newsId){
        return managerService.deleteNews(newsId);
    }

    @ResponseBody
    @RequestMapping("/changeValidTag")
    public Result changeValidTag(String isValid,String dataId,String dataType,String optManagerId){
        return managerService.changeValidTag(isValid,dataId,dataType,optManagerId);
    }

    @ResponseBody
    @RequestMapping("/addNews")
    public Result addNews(String newsInfo, String managerId){
        return managerService.addNews(newsInfo,managerId);
    }

    @ResponseBody
    @RequestMapping("/modifyNews")
    public Result modifyNews(String newsInfo, String newsId, String managerId){
        return managerService.modifyNews(newsInfo,newsId,managerId);
    }

    @ResponseBody
    @RequestMapping("/getShowPic")
    public Result getShowPic(int page,int number){
        return managerService.getShowPic(page,number);
    }

    @ResponseBody
    @RequestMapping("/uploadPic")
    public Result uploadPic(MultipartFile image, String newsTitle, String managerId){
        return managerService.uploadPic(image,newsTitle,managerId);
    }

    @ResponseBody
    @RequestMapping("/getVillageInfo")
    public Result getVillageInfo(String villageId,boolean isManager){
        return villageService.getVillageInfo(villageId,isManager);
    }

    @ResponseBody
    @RequestMapping("/getBeneficiaryInfo")
    public Result getBeneficiaryInfo(int page, int limit, String beneficiaryType, String villageId){
        return managerService.getBeneficiaryInfo(page,limit,beneficiaryType,villageId);
    }

    @ResponseBody
    @RequestMapping("/deleteBeneficiary")
    public Result deleteBeneficiary(String beneficiaryId){
        return managerService.deleteBeneficiary(beneficiaryId);
    }

    @ResponseBody
    @RequestMapping("/getDataInfoById")
    public Result getDataInfoById(String dataId,String dataType){
        return managerService.getDataInfoById(dataId,dataType);
    }

    @ResponseBody
    @RequestMapping("/addBeneficiary")
    public Result addBeneficiary(String beneficiaryInfo, String managerId){
        return managerService.addBeneficiary(beneficiaryInfo,managerId);
    }

    @ResponseBody
    @RequestMapping("/modifyBeneficiary")
    public Result modifyBeneficiary(String beneficiaryInfo, String newsId, String managerId){
        return managerService.modifyBeneficiary(beneficiaryInfo,newsId,managerId);
    }

    @ResponseBody
    @RequestMapping("/searchBeneficiaryByName")
    public Result searchBeneficiaryByName(String searchName,String villageId,int page,int limit){
        return managerService.searchBeneficiaryByName(searchName,villageId,page,limit);
    }

    @ResponseBody
    @RequestMapping("/getServiceInfo")
    public Result getServiceInfo(String serviceId,String serviceType){
        return managerService.getServiceInfo(serviceId,serviceType);
    }

    @ResponseBody
    @RequestMapping("/getServiceOptionInfo")
    public Result getServiceOptionInfo(String serviceId,String serviceType,String searchName,int page,int limit){
        return managerService.getServiceOptionInfo(serviceId,serviceType,searchName,page,limit);
    }

    @ResponseBody
    @RequestMapping("/modifyServiceOption")
    public Result modifyServiceOption(String serviceInfo, String optionId, String managerId){
        return managerService.modifyServiceOption(serviceInfo,optionId,managerId);
    }

    @ResponseBody
    @RequestMapping("/deleteServiceOption")
    public Result deleteServiceOption(String optionId){
        return managerService.deleteServiceOption(optionId);
    }

    @ResponseBody
    @RequestMapping("/modifyManager")
    public Result modifyManager(String managerInfo,String managerId,String optManagerId){
        return managerService.modifyManager(managerInfo,managerId,optManagerId);
    }

    @ResponseBody
    @RequestMapping("/deleteManager")
    public Result deleteManager(String managerId,String optManagerId){
        return managerService.deleteManager(managerId,optManagerId);
    }

    @ResponseBody
    @RequestMapping("/addManager")
    public Result addManager(String managerInfo,String optManagerId){
        return managerService.addManager(managerInfo,optManagerId);
    }

    @ResponseBody
    @RequestMapping("/uploadFile")
    public Result uploadFile(MultipartFile file,String optManagerId){
        return managerService.uploadFile(file,optManagerId);
    }
}
